/*
 * @lc app=leetcode.cn id=2500 lang=cpp
 *
 * [2500] 删除每行中的最大值
 */

// @lc code=start
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
    int deleteGreatestValue(vector<vector<int>> &grid)
    {
        const int m = grid.size();
        const int n = grid[0].size();

        for (auto &row : grid)
        {
            std::sort(row.begin(), row.end());
        }

        int ans = 0;

        for (size_t c = 0; c < n; c++)
        {
            int max_col = grid[0][c];
            for (size_t r = 0; r < m; r++)
            {
                max_col = max(max_col, grid[r][c]);
            }
            ans += max_col;
        }

        return ans;
    }
};
// @lc code=end
